<template>
  <div class="header">
    <div class="left">
      <div class="logo">
        <img src="https://lib.eqh5.com/eqx.layout/images/new_logo.svg" alt="">
      </div>

      <div class="menu">
        <el-menu mode="horizontal">
          <el-menu-item>免费模板</el-menu-item>
          <el-menu-item>开通会员</el-menu-item>
        </el-menu>
      </div>
    </div>

    <div class="user-info">
      <el-dropdown>
        <el-button>
          <span>{{ phone }}</span>
          <el-icon class="el-icon--right"><arrow-down /></el-icon>
        </el-button>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>我的作品</el-dropdown-item>
            <el-dropdown-item @click="$router.push({ name: 'CreateProduct' })">创建作品</el-dropdown-item>
            <el-dropdown-item @click="quit">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useUserStore } from '@/stores/user';
import { removeToken } from '@/utils/local';
import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus'
const router = useRouter()
const { phone, quitLogin } = useUserStore();
const quit = () => {
  quitLogin().then(() => {
    removeToken();
    router.push({ name: 'Login' });
    ElMessage.success('退出成功， 请重新登录')
  })
}
</script>


<style lang="scss" scoped>
.header {
  display: flex;
  justify-content: space-between;
  padding: 0 20px;
  height: 60px;

  .left {
    display: flex;
    flex: 1;

    .logo {
      display: flex;
      align-items: center;

      img {
        height: 30px;
      }
    }

    .menu {
      flex: 1;

      .el-menu--horizontal.el-menu {
        border: 0;
      }
    }
  }

  .user-info {
    display: flex;
    align-items: center;
  }


}
</style>